from lxml import etree

tree = etree.parse("基本语法.html")

# li_list = tree.xpath("//body/ul/li")
# 获取标签内容
# li_content = tree.xpath("//body/ul/li[@id]/text()")
# 属性特定值标签内容获取
# li_content = tree.xpath("//body/ul/li[@id='bajie']/text()")
# 标签属性值
# class_name = tree.xpath("//body/ul/li[@id='wukong']/@class")
# 包含
# li_content = tree.xpath("//body/ul/li[contains(@id,'e')]/text()")
# 首尾
# li_content = tree.xpath("//body/ul/li[starts-with(@id,'t')]/text()")
# 并交选择
# 选择id为wukong且class为monkey的标签内容
# li_content = tree.xpath("//body/ul/li[@id='wukong' and @class='monkey']/text()")
# 选择id为bajie 或者 id为 tangseng 的标签内容
# li_content = tree.xpath("//body/ul/li[@id='bajie' | @id='tangseng']/text()") 错误写法
li_content = tree.xpath("//body/ul/li[@id='bajie']/text() | //body/ul/li[@id='tangseng']/text()") 
print(li_content)
